/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package com.plian.system.controller.dp;

import com.plian.Tools.base.BaseController;
import com.plian.system.dto.dp.UprightDisciplinedDTO;
import com.plian.system.model.CommonCode;
import com.plian.system.model.R;
import com.plian.system.service.dp.IUprightDisciplinedService;
import com.plian.system.service.wf.FormWorkflowService;
import com.plian.system.vo.report.ReportReturnVO;
import com.plian.system.wrapper.dp.UprightDisciplinedWrapper;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 正风肃纪工作情况管理 控制器
 *
 * @author gangan
 * @since 2019-09-27
 */
@RestController
@AllArgsConstructor
@RequestMapping("api/uprightdisciplined")
public class UprightDisciplinedController extends BaseController {

	private IUprightDisciplinedService uprightDisciplinedService;

	private FormWorkflowService formWorkflowService;

	private UprightDisciplinedWrapper uprightDisciplinedWrapper;

//	/** TODO DEL
//	 * 详情
//	 */
//	@PostMapping("/detail")
//	public R<UprightDisciplinedVO> detail(@RequestBody UprightDisciplined uprightDisciplined) {
//		UprightDisciplined detail = uprightDisciplinedService.getOne(Condition.getQueryWrapper(uprightDisciplined));
//		UprightDisciplinedVO partyAccountableVO = uprightDisciplinedWrapper.entityToVO(detail);
//		R objResult = new R<UprightDisciplinedVO>(CommonCode.SUCCESS);
//		objResult.setPageData(partyAccountableVO);
//		return objResult;
//	}
//
//	/**
//	 * 分页
//	 */
//	@PostMapping("/list")
//	public ListResult<UprightDisciplinedVO> list(@RequestBody Query query) {
//		List<SearchEntity> entityList = query.getSearch();
//		if (query.getAscs()==null&&query.getDescs()==null){
//			query.setDescs("create_time");
//		}
//		QueryWrapper<UprightDisciplined> queryWrapper = SearchParamEntiy.getQueryWrapper(
//				Condition.getQueryWrapper(new UprightDisciplined()), entityList
//		);
//		TokenSearch<UprightDisciplined> tokenSearch = new TokenSearch<>();
//		tokenSearch.addTokenQuery(queryWrapper, query);
//
//		IPage<UprightDisciplined> pages = uprightDisciplinedService.page(Condition.getPage(query), queryWrapper);
//		ListResult<UprightDisciplinedVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//		listResult.setList(uprightDisciplinedWrapper.entityToVO(pages.getRecords()));
//		listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//		return listResult;
//	}
//
//	/**
//	 * 新增或修改
//	 */
//	@PostMapping("/submit")
//	@Resubmit(delaySeconds = 0)
//	public R submit(@Valid @RequestBody UprightDisciplined uprightDisciplined) {
//		if (uprightDisciplinedService.checkIsExisted(uprightDisciplined.getId(), uprightDisciplined.getCode())) {
//			String checkMessage = uprightDisciplinedService.checkFillingTime(uprightDisciplined);
//			if (StringUtil.isNotBlank(checkMessage)){
//				return new R(CustomCode.builder().message(checkMessage).code(1999).success(false).build());
//			}
//			boolean result = uprightDisciplinedService.saveOrUpdate(uprightDisciplined);
//			HashMap<String, Object> processVariable = new HashMap<>();
//			formWorkflowService.startProcessAndSimulate(String.valueOf(uprightDisciplined.getId()),uprightDisciplined.getFormType(),processVariable);
//
//			return result ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//		} else {
//			return new R(CustomCode.builder().message("单据编码已存在").code(1999).success(false).build());
//		}
//	}
//
//	/**
//	 * 删除
//	 */
//	@PostMapping("/remove")
//	public R remove(@RequestBody PageData pd) {
//		List<String> ids = (List<String>)pd.get("ids");
//		return uprightDisciplinedService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)))
//				? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}


	@PostMapping("/uprightDisciplineSummary")
	public R<ReportReturnVO> uprightDisciplineSummary(@RequestBody UprightDisciplinedDTO uprightDisciplinedDTO){
		ReportReturnVO reportReturnVO = uprightDisciplinedService.selectUprightDisciplineMain(uprightDisciplinedDTO);
		R<ReportReturnVO> results = new R<>(CommonCode.SUCCESS);
		results.setPageData(reportReturnVO);
		return results;
	}

}
